package com.qiaofei.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

@Slf4j
@Service
public class BaseServiceImpl {

    public void deleteImages(List<String> imageList){
        try {
            if (imageList.size() > 0) {
                String path = ResourceUtils.getURL("classpath:").getPath();
                File upload = new File(path);
                String uploadPath = upload.getAbsolutePath() + "/";
                for (String item :
                        imageList) {
                    if (item.equals("") == false) {
                        Path path2 = Paths.get(uploadPath + item);
                        if (Files.exists(path2)) {
                            Files.delete(path2);
                        }
                    }
                }
            }
        }catch (IOException e){
            log.error("图片删除失败: {}", e.getMessage());
        }

    }
}
